package com.draven.management.controller;

import com.draven.common.BaseController;
import com.draven.entity.News;
import com.draven.model.BaseConditionVO;
import com.draven.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Draven on 2017/4/16.
 * E-mail:draven1122@163.com
 */
@Controller("management.newsController")
@RequestMapping("/management/news")
public class NewsController extends BaseController {

    @Autowired
    private NewsService newsService;
    @RequestMapping("")
    public String main(){
        return "/management/news/main";
    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(BaseConditionVO vo){
        int totalCount = 0;
        try {
            totalCount = newsService.countNews(vo);
            System.out.println("OK");
            vo.setTotalCount(totalCount);
            List<News> newsList = newsService.listNews(vo);
            return listToJsonStrWithTotalCount(newsList);
        } catch (Exception e) {
            e.printStackTrace();
            return listToJsonStrWithTotalCount(null);
        }
    }
}
